package src.model.gameWorld;

import src.model.gameObject.*;
import src.model.gameObject.ability.*;

/**
 * <b>Overview</b><br>
 * <p>This class represetns a single technology.  once researched, it
 * modifies the PlayerLookupTable to reflect its research</p>
 * <br><br>
 * <b>Responsibilites</b><br>
 * <p>A Technology is responsibe for determing if it gets randomly
 * researched, and the updating the statistics table accordingly.</p>
 * <br><br>
 * <b>Collaborators</b>
 * <ul>
 * <li>PlayerLookupTable - Subcontractor</li>
 * </ul>
 * <br><br>
 * <b>Implementor</b> - Brent<br>
 * <b>Tester</b> - Tim<br>
 * 
 * @author Brent
 *
 */
public class Technology {
	private String myName, myDescription;
	private PlayerLookupTable myPlt;
	private GameObjectType myType;
	private GameObjectSubtype mySubtype;
	private AbilityType myAbility;
	private AbilityAttributes myAttribute;
	private float myProb, myAmount;
	private boolean affectsAll;
	
	public Technology(
			String name,
			String description,
			PlayerLookupTable plt,
			AbilityType affectedAbility,
			AbilityAttributes affectedAttribute,
			float increaseAmount,
			float initialProbability)
	{
		myName = name;
		myDescription = description;
		myPlt = plt;
		myType = null;
		mySubtype = null;
		myAbility = affectedAbility;
		myAttribute = affectedAttribute;
		myProb = initialProbability;
		affectsAll = true;
	}
	
	public Technology(
			String name,
			String description,
			PlayerLookupTable plt,
			GameObjectType affectedType,
			GameObjectSubtype affectedSubtype,
			AbilityType affectedAbility,
			AbilityAttributes affectedAttribute,
			float increaseAmount,
			float initialProbability)
	{
		myName = name;
		myDescription = description;
		myPlt = plt;
		myType = affectedType;
		mySubtype = affectedSubtype;
		myAbility = affectedAbility;
		myAttribute = affectedAttribute;
		myProb = initialProbability;
		affectsAll = false;
	}
	
	public boolean research()
	{
		if(Math.random() < myProb)
		{
			myProb = 0;
			
			if(affectsAll) myPlt.modifyStat(myAbility, myAttribute, myAmount);
			else myPlt.modifyStat(myType, mySubtype, myAbility, myAttribute, myAmount);
			
			return true;
		}
		else 
		{
			myProb += myProb * .35;
			
			return false;
		}
	}

	public String getMyDescription()
	{
		return myDescription;
	}

	public String getMyName()
	{
		return myName;
	}
}
